//
// Created by mac on 2/22/22.
//

using namespace std;

bool isBadVersion(int version);

int firstBadVersion(int n) {
    int left = 1;
    int right = n;
    while (left < right) {
        int mid = left + (right - left) / 2;
        if (isBadVersion(mid)) {
            right = mid;
        } else left = mid + 1;
    }
    return isBadVersion(left) ? left : -1;
}